<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-present http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace api\v1\model;
use think\Model;

class XmglZzjgXzqModel extends Model
{

    /**
     * 模型名称
     * @var string
     */
    protected $name = 'xmgl_zzjg_xzq';

    /**
     * 是否需要自动写入时间戳 如果设置为字符串 则表示时间字段的类型
     * @var bool|string
     */
    protected $autoWriteTimestamp = true;

    /**
     * 根据用户id号，返回用户的组织机构
     * @param int
     * @return array
     */
    public function getZzjgIdByUserID($userId){
        $zzjgId_arr = $this->where("user_id",$userId)->column('zzjg_id');

        if (empty($zzjgId_arr)) return null;
        
        $xzm = new XmglZzjgModel();
        $where[] = ['id','in',$zzjgId_arr];
        $where[] = ['status', '=', 1];
        $where[] = ['delete_time', '=', 0];
        $where[] = ['attrib', '>', 1];    //取得Bu或分支机构
        $zzjg_list = $xzm->where($where)->order("list_order","asc")->select()->toArray();

        return $zzjg_list;
    }

}
